<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-image: linear-gradient(135deg, #ddd, #000);
            border-radius: 50%;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>
<script>
    let box = document.querySelector('.box');
    var maxHeight = document.documentElement.scrollHeight - box.clientHeight;
    var timer = null;
    var speed = 10;

    timer = setInterval(() => {
        box.style.top = box.offsetTop + (speed++) + 'px';
        if (box.offsetTop >= maxHeight) {
            box.style.top = maxHeight + 'px';
            speed = -speed * 0.6;
            console.log(speed);
            if (Math.abs(speed) <= 3) {
                clearInterval(timer)
                setTimeout(clearInterval(timeX),1000)
            }
        }
    }, 50)

    var timeX = null;
    var speedX = 10;
    timeX = setInterval(() => {
        speedX = speedX * 0.99
        box.style.left = box.offsetLeft + speedX + 'px'
    }, 50)
</script>

</html>